#include "dextop.h"

#include <QApplication>
#include <QContextMenuEvent>
#include <QDesktopWidget>
#include <QMenu>
#include <QSettings>
#include <QX11Info>

#include <X11/Xlib.h>

Dextop::Dextop(QWidget *parent, Qt::WindowFlags f)
	: QLabel(parent, f)
	{
		setWindowFlags(Qt::FramelessWindowHint /* Qt::X11BypassWindowManagerHint */ |
					   Qt::WindowStaysOnBottomHint |
					   f);
		setAttribute(Qt::WA_X11NetWmWindowTypeDesktop, true);
		QSettings settings(QSettings::IniFormat, QSettings::UserScope, "TrueFusion", "Dextop");
		setGeometry(0, 0, QApplication::desktop()->width(), QApplication::desktop()->height());
		setScaledContents(true);
		setPixmap(QPixmap(settings.value("Desktop/wallpaper", QVariant("/usr/share/wallpapers/dexios.jpg")).toString()));
		show();
	}

Dextop::~Dextop()
	{
		//
	}

void Dextop::contextMenuEvent(QContextMenuEvent *event)
	{
		QMenu menu;
		menu.addAction("Logout", this, SLOT(closeX()));
		menu.exec(event->globalPos());
	}

void Dextop::closeX()
	{
		XCloseDisplay(QX11Info::display());
	}
